package me.DonglinPu.COMP2039;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Random;


/*
 * http://www.cs.waikato.ac.nz/ml/weka/index_documentation.html
 * http://www.cs.waikato.ac.nz/~ml/weka/
 */
/*
 * 111 proteins in .train
 * 17 proteins in .test
 * 
 * number of residues:
 * 3520 in .test
 * 18105 in .train
 */

public class Data {	
	private static final String START_OF_SEQUENCE = "<>";
	private static final String END_OF_SEQUENCE_1 = "end";
	private static final String END_OF_SEQUENCE_2 = "<end>";

	static final String OUTPUT_HELIX = "HelixTrain.dl";
	static final String OUTPUT_SHEET = "SheetTrain.dl";
	static final String OUTPUT_HELIX_TEST = "HelixTest.dl";
	static final String OUTPUT_SHEET_TEST = "SheetTest.dl";
	
	static final String MATLAB_INPUT = "Matlab.in";
	static final String MATLAB_OUTPUT = "Matlab.out";
	
	
	public static boolean isStart(String line){
		if(line.equals(START_OF_SEQUENCE)){
			return true;
		}
		return false;
	}
	
	public static boolean isEnd(String line){
		if(line.equals(END_OF_SEQUENCE_1)||line.equals(END_OF_SEQUENCE_2)){
			return true;
		}
		return false;
	}
	
	public static String aminoAcidSet(String letter){
		if(letter.equalsIgnoreCase("A")){
			AminoAcid alanine = new AminoAcid('A', "Alanine", "Ala");
			String A_binary = "10000"+"00000"+"00000"+"00000";
			return A_binary;
		} else if (letter.equalsIgnoreCase("R")){
			AminoAcid arginine = new AminoAcid('R', "Arginine", "Arg");
			String R_binary = "01000"+"00000"+"00000"+"00000";
			return R_binary;
		} else if (letter.equalsIgnoreCase("N")){
			AminoAcid asparagine = new AminoAcid('N', "Asparagine", "Asn");
			String N_binary = "00100"+"00000"+"00000"+"00000";
			return N_binary;
		} else if (letter.equalsIgnoreCase("D")){
			AminoAcid asparticAcid = new AminoAcid('D', "Aspartic acid",	"Asp");
			String D_binary = "00010"+"00000"+"00000"+"00000";
			return D_binary;
		} else if (letter.equalsIgnoreCase("C")){
			AminoAcid cysteine = new AminoAcid('C', "Cysteine",	"Cys");
			String C_binary = "00001"+"00000"+"00000"+"00000";
			return C_binary;
		} else if (letter.equalsIgnoreCase("E")){
			AminoAcid glutamicAcid = new AminoAcid('E', "Glutamic acid", "Glu");
			String E_binary = "00000"+"10000"+"00000"+"00000";
			return E_binary;
		} else if (letter.equalsIgnoreCase("Q")){
			AminoAcid glutamine = new AminoAcid('Q', "Glutamine", "Gln");
			String Q_binary = "00000"+"01000"+"00000"+"00000";
			return Q_binary;
		} else if (letter.equalsIgnoreCase("G")){
			AminoAcid glycine = new AminoAcid('G', "Glycine", "Gly");
			String G_binary = "00000"+"00100"+"00000"+"00000";
			return G_binary;
		} else if (letter.equalsIgnoreCase("H")){
			AminoAcid histidine = new AminoAcid('H', "Histidine", "His");
			String H_binary = "00000"+"00010"+"00000"+"00000";
			return H_binary;
		} else if (letter.equalsIgnoreCase("I")){
			AminoAcid isoleucine = new AminoAcid('I', "Isoleucine",	"Ile");
			String I_binary = "00000"+"00001"+"00000"+"00000";
			return I_binary;
		} else if (letter.equalsIgnoreCase("L")){
			AminoAcid leucine = new AminoAcid('L', "Leucine", "Leu");
			String L_binary = "00000"+"00000"+"10000"+"00000";
			return L_binary;
		} else if (letter.equalsIgnoreCase("K")){
			AminoAcid lysine = new AminoAcid('K', "Lysine",	"Lys");
			String K_binary = "00000"+"00000"+"01000"+"00000";
			return K_binary;
		} else if (letter.equalsIgnoreCase("M")){
			AminoAcid methionine = new AminoAcid('M', "Methionine",	"Met");
			String M_binary = "00000"+"00000"+"00100"+"00000";
			return M_binary;
		} else if (letter.equalsIgnoreCase("F")){
			AminoAcid phenylalanine = new AminoAcid('F', "Phenylalanine", "Phe");
			String F_binary = "00000"+"00000"+"00010"+"00000";
			return F_binary;
		} else if (letter.equalsIgnoreCase("P")){
			AminoAcid proline = new AminoAcid('P', "Proline", "Pro");
			String P_binary = "00000"+"00000"+"00001"+"00000";
			return P_binary;
		} else if (letter.equalsIgnoreCase("S")){
			AminoAcid serine = new AminoAcid('S', "Serine", "Ser");
			String S_binary = "00000"+"00000"+"00000"+"10000";
			return S_binary;
		} else if (letter.equalsIgnoreCase("T")){
			AminoAcid threonine = new AminoAcid('T', "Threonine", "Thr");
			String T_binary = "00000"+"00000"+"00000"+"01000";
			return T_binary;
		} else if (letter.equalsIgnoreCase("W")){
			AminoAcid tryptophan = new AminoAcid('W', "Tryptophan",	"Trp");
			String W_binary = "00000"+"00000"+"00000"+"00100";
			return W_binary;
		} else if (letter.equalsIgnoreCase("Y")){
			AminoAcid tyrosine = new AminoAcid('Y', "Tyrosine",	"Tyr");
			String Y_binary = "00000"+"00000"+"00000"+"00010";
			return Y_binary;
		} else if (letter.equalsIgnoreCase("V")){
			AminoAcid valine = new AminoAcid('V', "Valine",	"Val");
			String V_binary = "00000"+"00000"+"00000"+"00001";
			return V_binary;
		} else if (letter.equalsIgnoreCase("0")){
			return "00000"+"00000"+"00000"+"00000";
		}
		return "";
	}
	
	public static String aminoAcidSetMatlab(String letter){
		if(letter.equalsIgnoreCase("A")){
			AminoAcid alanine = new AminoAcid('A', "Alanine", "Ala");
			String A_binary = "1 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0";
			return A_binary;
		} else if (letter.equalsIgnoreCase("R")){
			AminoAcid arginine = new AminoAcid('R', "Arginine", "Arg");
			String R_binary = "0 1 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0";
			return R_binary;
		} else if (letter.equalsIgnoreCase("N")){
			AminoAcid asparagine = new AminoAcid('N', "Asparagine", "Asn");
			String N_binary = "0 0 1 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0";
			return N_binary;
		} else if (letter.equalsIgnoreCase("D")){
			AminoAcid asparticAcid = new AminoAcid('D', "Aspartic acid", "Asp");
			String D_binary = "0 0 0 1 0 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0";
			return D_binary;
		} else if (letter.equalsIgnoreCase("C")){
			AminoAcid cysteine = new AminoAcid('C', "Cysteine",	"Cys");
			String C_binary = "0 0 0 0 1 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0";
			return C_binary;
		} else if (letter.equalsIgnoreCase("E")){
			AminoAcid glutamicAcid = new AminoAcid('E', "Glutamic acid", "Glu");
			String E_binary = "0 0 0 0 0 "+"1 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0";
			return E_binary;
		} else if (letter.equalsIgnoreCase("Q")){
			AminoAcid glutamine = new AminoAcid('Q', "Glutamine", "Gln");
			String Q_binary = "0 0 0 0 0 "+"0 1 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0";
			return Q_binary;
		} else if (letter.equalsIgnoreCase("G")){
			AminoAcid glycine = new AminoAcid('G', "Glycine", "Gly");
			String G_binary = "0 0 0 0 0 "+"0 0 1 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0";
			return G_binary;
		} else if (letter.equalsIgnoreCase("H")){
			AminoAcid histidine = new AminoAcid('H', "Histidine", "His");
			String H_binary = "0 0 0 0 0 "+"0 0 0 1 0 "+"0 0 0 0 0 "+"0 0 0 0 0";
			return H_binary;
		} else if (letter.equalsIgnoreCase("I")){
			AminoAcid isoleucine = new AminoAcid('I', "Isoleucine",	"Ile");
			String I_binary = "0 0 0 0 0 "+"0 0 0 0 1 "+"0 0 0 0 0 "+"0 0 0 0 0";
			return I_binary;
		} else if (letter.equalsIgnoreCase("L")){
			AminoAcid leucine = new AminoAcid('L', "Leucine", "Leu");
			String L_binary = "0 0 0 0 0 "+"0 0 0 0 0 "+"1 0 0 0 0 "+"0 0 0 0 0";
			return L_binary;
		} else if (letter.equalsIgnoreCase("K")){
			AminoAcid lysine = new AminoAcid('K', "Lysine",	"Lys");
			String K_binary = "0 0 0 0 0 "+"0 0 0 0 0 "+"0 1 0 0 0 "+"0 0 0 0 0";
			return K_binary;
		} else if (letter.equalsIgnoreCase("M")){
			AminoAcid methionine = new AminoAcid('M', "Methionine",	"Met");
			String M_binary = "0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 1 0 0 "+"0 0 0 0 0";
			return M_binary;
		} else if (letter.equalsIgnoreCase("F")){
			AminoAcid phenylalanine = new AminoAcid('F', "Phenylalanine", "Phe");
			String F_binary = "0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 1 0 "+"0 0 0 0 0";
			return F_binary;
		} else if (letter.equalsIgnoreCase("P")){
			AminoAcid proline = new AminoAcid('P', "Proline", "Pro");
			String P_binary = "0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 1 "+"0 0 0 0 0";
			return P_binary;
		} else if (letter.equalsIgnoreCase("S")){
			AminoAcid serine = new AminoAcid('S', "Serine", "Ser");
			String S_binary = "0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"1 0 0 0 0";
			return S_binary;
		} else if (letter.equalsIgnoreCase("T")){
			AminoAcid threonine = new AminoAcid('T', "Threonine", "Thr");
			String T_binary = "0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"0 1 0 0 0";
			return T_binary;
		} else if (letter.equalsIgnoreCase("W")){
			AminoAcid tryptophan = new AminoAcid('W', "Tryptophan",	"Trp");
			String W_binary = "0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 1 0 0";
			return W_binary;
		} else if (letter.equalsIgnoreCase("Y")){
			AminoAcid tyrosine = new AminoAcid('Y', "Tyrosine",	"Tyr");
			String Y_binary = "0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 1 0";
			return Y_binary;
		} else if (letter.equalsIgnoreCase("V")){
			AminoAcid valine = new AminoAcid('V', "Valine",	"Val");
			String V_binary = "0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 1";
			return V_binary;
		} else if (letter.equalsIgnoreCase("0")){
			return "0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0 "+"0 0 0 0 0";
		}
		return "";
	}
	
	public static void writeBinary(String hOrE, String input_file_name, String output_file_name) throws IOException{
		FileInputStream fis = new FileInputStream(input_file_name);
		DataInputStream dis = new DataInputStream(fis);
		BufferedReader br = new BufferedReader(new InputStreamReader(dis));
		
		FileWriter fw = new FileWriter(output_file_name);
		BufferedWriter bw = new BufferedWriter(fw);
		int positive = 1;
		int negative = 0;

		boolean firstLine = true;
		boolean endOfDoc = false;
		String a1 = null, a2 = null, a3 = null, a4 = null, a5 = null;
		String r = null;
		int r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0;
		String line = br.readLine();
		while(line != null && !line.equals("")){
			while(Data.isStart(line) || Data.isEnd(line)){
				if(firstLine){
					a1 = Data.aminoAcidSet("0");
					a2 = Data.aminoAcidSet("0");
					//Amino3
					line = br.readLine();
					if(Data.isStart(line)||Data.isEnd(line)){
						line = br.readLine();
					} else if(line.equals("")){
						endOfDoc = true;
						break;
					}
					a3 = Data.aminoAcidSet(""+line.charAt(0));
					if((r = ""+line.charAt(2)).equalsIgnoreCase(hOrE)){
						r3 = positive;
					} else {
						r3 = negative;
					}
					//Amino4
					line = br.readLine();
					a4 = Data.aminoAcidSet(""+line.charAt(0));
					if((r = ""+line.charAt(2)).equalsIgnoreCase(hOrE)){
						r4 = positive;
					} else {
						r4 = negative;
					}
					//Amino5
					line = br.readLine();
					a5 = Data.aminoAcidSet(""+line.charAt(0));
					if((r = ""+line.charAt(2)).equalsIgnoreCase(hOrE)){
						r5 = positive;
					} else {
						r5 = negative;
					}
					bw.write(toWrite(a1, a2, a3, a4, a5, r3));
//					bw.write("[" + a1 + " " + a2 + " " + a3 + " " + a4 + " " + a5 + " 1]" + r3 + "\r\n");
					firstLine = false;
				}
				while(true){
					a1 = a2;
					a2 = a3;
					a3 = a4;
					a4 = a5;
					r1 = r2;
					r2 = r3;
					r3 = r4;
					r4 = r5;
					line = br.readLine();
					if(Data.isStart(line) || Data.isEnd(line)){
						String temp = Data.aminoAcidSet("0");
						firstLine = true;
						bw.write(toWrite(a1,a2,a3,a4,temp,r3));
//						bw.write("[" + a1 + "" + a2 + "" + a3 + "" + a4 + "" + temp + "1]" + r3 + "\r\n");
						bw.write(toWrite(a2,a3,a4,temp,temp,r4));
//						bw.write("[" + a2 + "" + a3 + "" + a4 + "" + temp + "" + temp + "1]" + r4 + "\r\n");
						bw.write("==\r\n");
						break;
					}
					a5 = Data.aminoAcidSet(""+line.charAt(0));
					if((r = ""+line.charAt(2)).equalsIgnoreCase(hOrE)){
						r5 = positive;
					} else {
						r5 = negative;
					}
					bw.write(toWrite(a1,a2,a3,a4,a5,r3));
//					bw.write("[" + a1 + " " + a2 + " " + a3 + " " + a4 + " " + a5 + " 1]" + r3 + "\r\n");
				}
			}
			if(endOfDoc){
				break;
			}
			line = br.readLine();
		}
		
		bw.close();
	}
	
	private static String toWrite(String a1, String a2, String a3, String a4, String a5, int r){
		return "[" + a1 + "" + a2 + "" + a3 + "" + a4 + "" + a5 + "1]" + r + "\r\n";
	}
	
	public static void writeProteins() throws IOException{
		FileInputStream fis = new FileInputStream("protein-secondary-structure.train");
		DataInputStream dis = new DataInputStream(fis);
		BufferedReader br = new BufferedReader(new InputStreamReader(dis));
		
		FileWriter fw;
		BufferedWriter bw;
		
		String output = "";
		int count = 0;
		String protein = "";
		String results = "";
		String aminoAcid = "";
		String he_ = "";
		
		boolean endOfProtein = false;

		String line = br.readLine();
		while(line != null && !line.equals("")){		
			line = br.readLine();
			if(Data.isEnd(line)){
				line = br.readLine();
			} 
			if(Data.isStart(line)){
				count++;
//				output = "D:\\Study\\Workspace\\COMP2039AI\\proteins\\"+count + ".pro";// TODO Windows
				output = "../proteins/"+count + ".pro";// linux
				fw = new FileWriter(new File(output));
				bw = new BufferedWriter(fw);
				bw.write(protein + "\r\n" + results);
				bw.close();
				protein = "";
				results = "";
				line = br.readLine();
			}
			if(line.equals("")){
				count++;
//				output = "D:\\Study\\Workspace\\COMP2039AI\\proteins\\"+count + ".pro";// TODO Windows
				output = "../proteins/"+count + ".pro";// linux
				fw = new FileWriter(new File(output));
				bw = new BufferedWriter(fw);
				bw.write(protein + "\r\n" + results);
				bw.close();
				line = br.readLine();
				break;
			}
			aminoAcid = ""+line.charAt(0);
			he_ = ""+line.charAt(2);

			protein = protein.concat(aminoAcid);
			results = results.concat(he_);
		}
	}

	
	public static void randomTrainingSet() throws IOException{
		ArrayList<Integer> used = new ArrayList<Integer>();
		int readNext = 0;
		Random a = new Random();
		long sysMilli = System.currentTimeMillis()/1000;
		String input = "";
		String output = "random-protein-"+sysMilli;
		String output_test = "random-protein-test-"+sysMilli;

		FileInputStream fis;
		DataInputStream dis;
		BufferedReader br;
		FileWriter fw = new FileWriter(new File(output));
		BufferedWriter bw = new BufferedWriter(fw);
		FileWriter testFw = new FileWriter(new File(output_test));
		BufferedWriter testBw = new BufferedWriter(testFw);
		
		String protein = "";
		String results = "";
		
		for(int i = 0; i < 111; i++){
			while(true){
				readNext = a.nextInt(111) + 1;
				if(!used.contains(readNext)){
					used.add(readNext);
					break;
				}
			}
			input = readNext + ".pro";
//			fis = new FileInputStream("D:\\Study\\Workspace\\COMP2039AI\\proteins\\"+input);// TODO Windows
			fis = new FileInputStream("../proteins/"+input);//Linux
			dis  = new DataInputStream(fis);
			br = new BufferedReader(new InputStreamReader(dis));
			protein = br.readLine();
			results = br.readLine();
			if(i<100){
				bw.write("<>\r\n");
				for(int j = 0; j < protein.length(); j++){
					bw.write(protein.charAt(j) + " " + results.charAt(j) + "\r\n");
				}
				bw.write("<end>\r\n");
			} else {
				testBw.write("<>\r\n");
				for(int j = 0; j < protein.length(); j++){
					testBw.write(protein.charAt(j) + " " + results.charAt(j) + "\r\n");
				}
				testBw.write("<end>\r\n");
			}
		}
		bw.write("\r\n");
		bw.close();
		testBw.write("\r\n");
		testBw.close();
		writeBinary("h", output, OUTPUT_HELIX);
		writeBinary("e", output, OUTPUT_SHEET);
		writeBinary("h", output_test, OUTPUT_HELIX_TEST);
		writeBinary("e", output_test, OUTPUT_SHEET_TEST);
		
//		writeToFitMatlab(output, MATLAB_INPUT, MATLAB_OUTPUT);
	}

	private static void writeToFitMatlab(String output, String matlabInput, String matlabOutput) throws IOException {
		FileInputStream fis = new FileInputStream(output);
		DataInputStream dis = new DataInputStream(fis);
		BufferedReader br = new BufferedReader(new InputStreamReader(dis));

		FileWriter fw_in = new FileWriter(new File(matlabInput));// "Matlab.in"
		BufferedWriter inputWriter = new BufferedWriter(fw_in);
		
		FileWriter fw_out = new FileWriter(new File(matlabOutput));// "Matlab.out"
		BufferedWriter outputWriter = new BufferedWriter(fw_out);
		
		boolean firstLine = true;
		boolean endOfDoc = false;
		String a1 = null, a2 = null, a3 = null, a4 = null, a5 = null;
		String r = null;// result
		String r1 = "0,0,0", r2 = "0,0,0", r3 = "", r4 = "", r5 = "";
		String line = br.readLine();
		while(line != null && !line.equals("")){
			while(Data.isStart(line) || Data.isEnd(line)){
				if(firstLine){
					a1 = Data.aminoAcidSetMatlab("0");
					a2 = Data.aminoAcidSetMatlab("0");
					//Amino3
					line = br.readLine();
					if(Data.isStart(line)||Data.isEnd(line)){
						line = br.readLine();
					} else if(line.equals("")){
						endOfDoc = true;
						break;
					}
					a3 = Data.aminoAcidSetMatlab(""+line.charAt(0));
					if((r = ""+line.charAt(2)).equalsIgnoreCase("h")){
						r3 = "1,0,0";
					} else if((r = ""+line.charAt(2)).equalsIgnoreCase("e")){
						r3 = "0,1,0";
					} else {
						r3 = "0,0,1";
					}
					//Amino4
					line = br.readLine();
					a4 = Data.aminoAcidSetMatlab(""+line.charAt(0));
					if((r = ""+line.charAt(2)).equalsIgnoreCase("h")){
						r4 = "1,0,0";
					} else if((r = ""+line.charAt(2)).equalsIgnoreCase("e")){
						r4 = "0,1,0";
					} else {
						r4 = "0,0,1";
					}
					//Amino5
					line = br.readLine();
					a5 = Data.aminoAcidSetMatlab(""+line.charAt(0));
					if((r = ""+line.charAt(2)).equalsIgnoreCase("h")){
						r5 = "1,0,0";
					} else if((r = ""+line.charAt(2)).equalsIgnoreCase("e")){
						r5 = "0,1,0";
					} else {
						r5 = "0,0,1";
					}
					inputWriter.write(a1 + " " + a2 + " " + a3 + " " + a4 + " " + a5 + "\r\n");
					outputWriter.write(r3 + "\r\n");
					firstLine = false;
				}
				while(true){
					a1 = a2;
					a2 = a3;
					a3 = a4;
					a4 = a5;
					r1 = r2;
					r2 = r3;
					r3 = r4;
					r4 = r5;
					line = br.readLine();
					if(Data.isStart(line) || Data.isEnd(line)){
						String temp = Data.aminoAcidSetMatlab("0");
						firstLine = true;
						inputWriter.write(a1 + " " + a2 + " " + a3 + " " + a4 + " " + temp + "\r\n");
						outputWriter.write(r3 + "\r\n");
						inputWriter.write(a2 + " " + a3 + " " + a4 + " " + temp + " " + temp + "\r\n");
						outputWriter.write(r4 + "\r\n");
						break;
					}
					a5 = Data.aminoAcidSetMatlab(""+line.charAt(0));
					if((r = ""+line.charAt(2)).equalsIgnoreCase("h")){
						r5 = "1,0,0";
					} else if((r = ""+line.charAt(2)).equalsIgnoreCase("e")){
						r5 = "0,1,0";
					} else {
						r5 = "0,0,1";
					}
					inputWriter.write(a1 + " " + a2 + " " + a3 + " " + a4 + " " + a5 + "\r\n");
					outputWriter.write(r3 + "\r\n");
				}
			}
			if(endOfDoc){
				break;
			}
			line = br.readLine();
		}
		
		inputWriter.close();
		outputWriter.close();
	}
	
//	public static void writeResults000() throws IOException{
//		FileInputStream fis = new FileInputStream("protein-secondary-structure.train");
//		DataInputStream dis = new DataInputStream(fis);
//		BufferedReader br = new BufferedReader(new InputStreamReader(dis));
//		FileWriter fw = new FileWriter(new File("results000.dl"));
//		BufferedWriter bw = new BufferedWriter(fw);
//		
//		int positive = 1;
//		int negative = 0;
//
//		boolean firstLine = true;
//		boolean endOfDoc = false;
//		String a1 = null, a2 = null, a3 = null, a4 = null, a5 = null;
//		String r = null;
//		int r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0;
//		String line = br.readLine();
//		while(line != null && !line.equals("")){
//			while(Data.isStart(line) || Data.isEnd(line)){
//				if(firstLine){
//					a1 = Data.aminoAcidSet("0");
//					a2 = Data.aminoAcidSet("0");
//					//Amino3
//					line = br.readLine();
//					if(Data.isStart(line)||Data.isEnd(line)){
//						line = br.readLine();
//					} else if(line.equals("")){
//						endOfDoc = true;
//						break;
//					}
//					a3 = Data.aminoAcidSet(""+line.charAt(0));
//					if((r = ""+line.charAt(2)).equalsIgnoreCase(hOrE)){
//						r3 = positive;
//					} else {
//						r3 = negative;
//					}
//					//Amino4
//					line = br.readLine();
//					a4 = Data.aminoAcidSet(""+line.charAt(0));
//					if((r = ""+line.charAt(2)).equalsIgnoreCase(hOrE)){
//						r4 = positive;
//					} else {
//						r4 = negative;
//					}
//					//Amino5
//					line = br.readLine();
//					a5 = Data.aminoAcidSet(""+line.charAt(0));
//					if((r = ""+line.charAt(2)).equalsIgnoreCase(hOrE)){
//						r5 = positive;
//					} else {
//						r5 = negative;
//					}
//					bw.write(toWrite(a1, a2, a3, a4, a5, r3));
////					bw.write("[" + a1 + " " + a2 + " " + a3 + " " + a4 + " " + a5 + " 1]" + r3 + "\r\n");
//					firstLine = false;
//				}
//				while(true){
//					a1 = a2;
//					a2 = a3;
//					a3 = a4;
//					a4 = a5;
//					r1 = r2;
//					r2 = r3;
//					r3 = r4;
//					r4 = r5;
//					line = br.readLine();
//					if(Data.isStart(line) || Data.isEnd(line)){
//						String temp = Data.aminoAcidSet("0");
//						firstLine = true;
//						bw.write(toWrite(a1,a2,a3,a4,temp,r3));
////						bw.write("[" + a1 + "" + a2 + "" + a3 + "" + a4 + "" + temp + "1]" + r3 + "\r\n");
//						bw.write(toWrite(a2,a3,a4,temp,temp,r4));
////						bw.write("[" + a2 + "" + a3 + "" + a4 + "" + temp + "" + temp + "1]" + r4 + "\r\n");
//						bw.write("==\r\n");
//						break;
//					}
//					a5 = Data.aminoAcidSet(""+line.charAt(0));
//					if((r = ""+line.charAt(2)).equalsIgnoreCase(hOrE)){
//						r5 = positive;
//					} else {
//						r5 = negative;
//					}
//					bw.write(toWrite(a1,a2,a3,a4,a5,r3));
////					bw.write("[" + a1 + " " + a2 + " " + a3 + " " + a4 + " " + a5 + " 1]" + r3 + "\r\n");
//				}
//			}
//			if(endOfDoc){
//				break;
//			}
//			line = br.readLine();
//		}
//		
//		bw.close();
//	}

}
